package com.example.controller;

import com.example.util.ResultUtil;
import org.apache.shiro.authz.AuthorizationException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

@RestControllerAdvice
public class ExceptionAdvice {

    /**
     * 全局的异常捕获，所有Controller权限注解判断时抛了异常，在这里捕获
     *
     * @param req 请求
     * @return
     */
    @ExceptionHandler(AuthorizationException.class)
    public Object authorizationExceptionHandler(HttpServletRequest req) {
        return ResultUtil.unAuthorized(req.getServletPath()); // 403
    }
}
